﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MINERP.DigitalOutput
{
    public partial class FrmAutoDistributeRunning : Form
    {
        //参数
        //属性
        public FrmDigitalMain2 fdm { get; set; }

        public int PhotoNum { get; set; }               //自动分配的照片总数

        public FrmAutoDistributeRunning()
        {
            InitializeComponent();
        }

        private void FrmAutoDistributeRunning_Load(object sender, EventArgs e)
        {

        }

        #region 关闭按钮
        private void FrmAutoDistributeRunning_FormClosing(object sender, FormClosingEventArgs e)
        {
            fdm.ttRefresh.Enabled = true;
            fdm.tsAutoDistribute_Click(sender, e);
        }
        #endregion 

        //30秒执行一次自动分配
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                fdm.ttRefresh_Tick(sender, e);
                PhotoNum += fdm.AutoDistributePhotoNum;
                lblPhotoNum.Text = PhotoNum.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //开始自动分配按钮
        private void btnStartAuto_Click(object sender, EventArgs e)
        {
            btnStartAuto.Enabled = false;
            btnStopAuto.Enabled = true;
            lblToolTip.Visible = true;
            timer1.Enabled = true;
            timer2.Enabled = true;
        }

        //停止自动分配
        private void btnStopAuto_Click(object sender, EventArgs e)
        {
            btnStartAuto.Enabled = true;
            btnStopAuto.Enabled = false;
            lblToolTip.Visible = false ;
            timer1.Enabled = false;
            timer2.Enabled = false;
        }

        public void AutoDistribute()
        {
            fdm.AutoDistributePrinter();
        }

        //自动分配进度条的运行控制
        private void timer2_Tick(object sender, EventArgs e)
        {
            process.Position += 1;
            if (process.Position >= process.Properties.Maximum)
            {
                process.Position = process.Properties.Minimum;
            }
        }

        //关闭按钮无效
        //const int WM_Close = 0x0010;
        //protected override void WndProc(ref Message m)
        //{
        //    if (m.Msg == WM_Close)
        //        return;
        //    base.WndProc(ref m);
        //} 
    }
}
